//
// Matte.cpp for  in /home/herpec_j/Dropbox/Projets/raytracer-2016/Sources/Materials/
//
// Made by Jonathan
// Login   <ledey_l@epitech.net>
//
// Started on  Wed Sep 25 23:52:39 2013 Jonathan
// Last update Thu Sep 26 00:37:11 2013 Jonathan
//

#include		<cstdlib>

#include		"Materials/Matte.hpp"

namespace		Materials
{
  Matte::Matte(void) : Material(), mAmbientBRDF(new BRDFs::Lambertian), mDiffuseBRDF(new BRDFs::Lambertian)
  {
    return;
  }

  Matte::Matte(Matte const &rOther) : Material(rOther), mAmbientBRDF(rOther.mAmbientBRDF->Clone()), mDiffuseBRDF(rOther.mDiffuseBRDF->Clone())
  {
    return;
  }

  Matte			&Matte::operator=(Matte const &rOther)
  {
    if (this != &rOther)
      {
	Material::operator=(rOther);
	delete mAmbientBRDF;
	mAmbientBRDF = rOther.mAmbientBRDF->Clone();
	delete mDiffuseBRDF;
	mDiffuseBRDF = rOther.mDiffuseBRDF->Clone();
      }
    return (*this);
  }

  Matte			*Matte::Clone(void) const
  {
    return (new Matte(*this));
  }

  void			Matte::SetKa(long double rKa)
  {
    mAmbientBRDF->SetKd(rKa);
  }

  void			Matte::SetKd(long double rKd)
  {
    mDiffuseBRDF->SetKd(rKd);
  }

  void			Matte::SetCd(Maths::Color const &rColor)
  {
    mAmbientBRDF->SetCd(rColor);
    mDiffuseBRDF->SetCd(rColor);
  }

  void			Matte::SetCd(long double rR, long double rG, long double rB)
  {
    mAmbientBRDF->SetCd(rR, rG, rB);
    mDiffuseBRDF->SetCd(rR, rG, rB);
  }

  void			Matte::SetCd(long double rColor)
  {
    mAmbientBRDF->SetCd(rColor);
    mDiffuseBRDF->SetCd(rColor);
  }

  Maths::Color		Matte::Shade(Maths::ShadeRec const &rShadeRec)
  {
    /*    Maths::Vector	wo = -rShadeRec.mRay.GetDirection();
    Maths::Color	color = mAmbientBRDF->Rho(rShadeRec, wo) * rShadeRec.mWorld.GetAmbientPtr()->GetRadiance(rShadeRec);
    int			num_lights = rShadeRec.mWorld.GetLights().size();
    Maths::Vector	wi;
    long double		n_dot_wi;

    for (unsigned short i = 0;
	 i < num_lights;
	 ++i)
      {
	wi = rShadeRec.mWorld.GetLights()[i]->GetDirection(rShadeRec);
	n_dot_wi = rShadeRec.mNormal * wi;
	if (n_dot_wi > 0.0)
	  {
	    color += mDiffuseBRDF->F(rShadeRec, wo, wi) * rShadeRec.mWorld.GetLights()[i]->GetRadiance(rShadeRec) * n_dot_wi;
	  }
      }
      return (color);*/
    (void) rShadeRec;
    return (Maths::Color());
  }

  Matte::~Matte(void)
  {
    delete mAmbientBRDF;
    delete mDiffuseBRDF;
  }
};
